package com.taru.houseapp.controller;

import com.taru.houseapp.commen.JsonResult;
import com.taru.houseapp.entity.HotCity;
import com.taru.houseapp.entity.HotSreach;
import com.taru.houseapp.entity.House;
import com.taru.houseapp.entity.LoopImage;
import com.taru.houseapp.service.IMarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.*;
import java.util.List;

@RestController
public class MarketController {

    @Autowired
    IMarketService marketService;

    /**
     * 轮播图
     * @return
     */
    @RequestMapping(value = "/image/loop",method = RequestMethod.GET)
    public JsonResult queryRotationImage(){
        JsonResult result=null;
        try{
            List<LoopImage> images=marketService.queryRotationImage();
            result=new JsonResult(200,"获取成功",images);
        }catch (Exception e){
            e.printStackTrace();
            result=new JsonResult(500,"服务器内部错误",e.getMessage());
        }
        return result;
    }

    /**
     * 查询热门城市
     * @return
     */
    @RequestMapping(value = "/hotcity",method = RequestMethod.GET)
    public JsonResult queryCityHot(){
        JsonResult result=null;
        try{
            List<HotCity> cities=marketService.queryCityHot();
            result=new JsonResult(200,"获取成功",cities);
        }catch (Exception e){
            e.printStackTrace();
            result=new JsonResult(500,"服务器内部错误",e.getMessage());
        }
        return result;
    }

    /**
     * 查询热门搜索小区名字
     * @return
     */
    @RequestMapping(value = "/hot/address",method = RequestMethod.GET)
   public  JsonResult queryHotVillage(String cityName){
        JsonResult result=null;
        if(cityName ==null || cityName.length()<=0){
            result=new JsonResult(404,"参数错误");
            return result;
        }
        try{
            List<HotSreach> sreaches=marketService.queryHotVillage(cityName);
            result=new JsonResult(200,"获取成功",sreaches);
        }catch (Exception e){
            e.printStackTrace();
            result=new JsonResult(500,"服务器内部错误",e.getMessage());
        }
        return result;
   }
}
